<template>
  <view class="body">
    <view class="top_info">
      <image class="color_img" src="https://ainengli.meilianshuke.com/jkhx/answerBg.png" />
      <view class="title">健康饮食问卷</view>
      <view class="label">
        <image class="label_img" src="https://ainengli.meilianshuke.com/jkhx/common/shield.png" />
        <text>复美医疗大模型</text>
      </view>
      <image class="bg_img" src="https://ainengli.meilianshuke.com/jkhx/questionBg.png" />
    </view>
    <view class="remark">
      <view class="remark_title">尊敬的{{ userInfo.patName }}会员您好:</view>
      <text class="remark_text"
        >请您先填写饮食问卷，以便于我们了解您的当前状况。我们将根据您的情况为您制定饮食方案。</text
      >
    </view>
    <view class="fixed">
      <button class="confirm_btn" @tap="begin">开始答题</button>
    </view>
  </view>
</template>

<script setup lang="ts">
import { onLoad, onShow } from '@dcloudio/uni-app'
import { scale_list, scale_save } from '@/api/body'
import { ref, reactive } from 'vue'
import { debounce, throttle, deepCopy } from '@/utils/tools'
import store from '@/store'

const userInfo = ref({})
const questionInfo = ref({})
const questionList = ref([])

let currentId = ''

onShow(() => {
  userInfo.value = JSON.parse(uni.getStorageSync('userInfo')).patientInfo
  if (!currentId || currentId !== userInfo.value.empi) {
    currentId = deepCopy(userInfo.value.empi)
    getData()
  }
})

const getData = () => {
  // currentId
  scale_list(currentId).then((res) => {
    if (res.code === 0) {
      questionInfo.value = res.data[0]
      const arr = JSON.parse(res.data[0].questions)
      arr.forEach((item) => {
        item.answer = ''
        item.options = JSON.parse(item.options)
      })
      questionList.value = arr
    }
  })
}

const begin = () => {
  if (store.state.CLIENTTYPE === 'checkAfterMini') {
    uni.redirectTo({
      url: '/packA/pages/questionaireMerge/index?type=save'
    })
  } else {
    uni.redirectTo({
      url: '/packA/pages/threeTypeQuestion/index'
    })
  }
}
</script>

<style lang="scss" scoped>
.body {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100vh;
  padding-bottom: 184rpx;
  overflow: auto;

  .top_info {
    position: relative;
    height: 512rpx;
    padding: 48rpx 32rpx;
    background: linear-gradient(180deg, rgb(172 235 242 / 28%) 0%, #f3f7f8 100%);

    .color_img {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 328rpx;
    }

    .title {
      position: relative;
      z-index: 2;
      margin-bottom: 16rpx;
      font-size: 48rpx;
      font-weight: bold;
      color: #222;
    }

    .label {
      position: relative;
      z-index: 2;
      display: inline-block;
      padding: 10rpx 32rpx;
      font-size: 26rpx;
      font-weight: 400;
      color: #fff;
      background: #00d1b6;
      border: 1rpx solid #00d1b6;
      border-radius: 28rpx;

      .label_img {
        width: 28rpx;
        height: 28rpx;
        margin-right: 8rpx;
        transform: translateY(4rpx);
      }
    }

    .bg_img {
      position: absolute;
      top: 0;
      right: 0;
      z-index: 1;
      width: 320rpx;
      height: 334rpx;
    }
  }

  .remark {
    position: relative;
    z-index: 2;
    padding: 32rpx;
    margin: 0 32rpx;
    margin-top: -235rpx;
    background: #fff;
    border: 1rpx solid #fff;
    border-radius: 16rpx;

    .remark_title {
      margin-bottom: 32rpx;
      font-size: 36rpx;
      font-weight: 600;
      color: #222;
    }

    .remark_text {
      display: inline-block;
      font-size: 32rpx;
      font-weight: 400;
      line-height: 64rpx;
      color: #666;
      text-align: justify;
    }
  }

  .fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 10;
    box-sizing: border-box;
    width: 100%;
    padding: 24rpx 32rpx;
    padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
    background: #fff;

    .confirm_btn {
      width: 100%;
      font-size: 32rpx;
      font-weight: bold;
      color: #fff;
      background: #00d1b6;
      border-radius: 44rpx;
    }
  }
}
</style>
